home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7253 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: pegasus.montclair.edu!harmon
  2. From: harmon@pegasus.montclair.edu (Derek Harmon)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to open include path by fopen in DOS C program?
  5. Date: 12 Feb 1996 15:56:02 -0500
  6. Organization: Montclair State University
  7. Message-ID: <harmon.824157381@pegasus.montclair.edu>
  8. References: <4fhkvd$120@news.hkstandard.com>
  9. NNTP-Posting-Host: pegasus.montclair.edu
  10. X-Newsreader: NN version 6.5.0 #68 (NOV)
  11.  
  12. khtse@hkstandard.com (khtse) writes:
  13. >    It can open file name by fopen only but not include path name under
  14. >DOS C program, so how to solve it?
  15.  
  16. FILE *fp;
  17.  
  18. if ((fp = fopen("\\TEST\\CONFIG.DAT", "rt)) == NULL) {
  19.    fputs(stderr,"Cannot open Config File for reading.");
  20.    return 1;
  21. }
  22.  
  23.    Notice the \\'s in the filespec string, these are necessary because C
  24. defines \ as an escape character, which you normally use in \n or \t.  To
  25. actually have the C compiler include a \ in a piece of text, you must use
  26. \\.  In a filespec, fopen for DOS will then convert to D:\TEST\CONFIG.DAT,
  27. where D is your current drive.  Similarly, a filespec such as "F:\\FOO.BAR"
  28. would look in the root-directory of drive F:.
  29.  
  30. >    And in the network environment, if C program is reading the text files
  31. >and the other pc to write and update this text file, what will happen?
  32.  
  33.    Your PC will explode.  B)  Actually if you have something to watchdog
  34. your system like SHARE.EXE for DOS 3.3 and later, you will get a Sharing
  35. Violation.  If you want to program to allow this to occur, Share or most
  36. equivalent network drivers feature functions that will lock files and records,
  37. to prevent the problem you describe from happening.  In general, your Read
  38. and Write functions would have to:
  39.  
  40.    1.  Attempt to lock the record(s) or file(s) you wish to read/write.
  41.    2.  When Share or your Network driver gives your program exclusive
  42.    permission to those records/files, you read/write them.
  43.    3.  Subsequently you must unlock the record(s) or file(s) to which you
  44.    requested a read or write.
  45.  
  46.    Usually the implementation is that multiple concurrent reads are permis-
  47. sible, but if any writing is being done, reads will be blocked by DOS or the
  48. network operating system.
  49.  
  50.    For details on writing Read/Write code for use with DOS's Share, consult
  51. any good PC/DOS Programmer's Manual.  For other networks, consult their
  52. API references.  The specifics are OS-specific and are best asked in another
  53. more relevent newsgroup.
  54.                                                     -- Stone
  55.  
  56. --
  57. # Derek Harmon (aka Stonelight)    harmon@pegasus.montclair.edu
  58. # - Computer Science Undergrad, Montclair State University, NJ
  59. # - My views are my own, nobody else is this creative.  3;)>
  60. ... This cookie is void where prohibited, licensed, or taxed.
  61.